﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Eis51.CampanyCMS.Business;
using Eis51.CampanyCMS.Business.NewsManager;
using Eis51.CampanyCMS.FrameWork;
using Eis51.CampanyCMS.Model.Bus;
using Eis51.CampanyCMS.Model.NewsManager;

using Eis51.CampanyCMS.Business.Bus;
using Eis51.CampanyCMS.Model;


namespace Eis51.Web.Admin.NewsManager
{
    /// <summary>
    /// NewMarket 的摘要说明。
    /// </summary>
    public partial class NewMarket : BasePage
    {
        protected System.Web.UI.HtmlControls.HtmlInputHidden content1;



        /// <summary>
        /// NewsID 0:新增/否则修改
        /// </summary>
        private string seqno
        {
            get
            {
                if (Request["seqno"] == null)
                {
                    return "0";
                }
                else
                {
                    return (string)Request["seqno"];
                }
            }
        }

        public string Typecode
        {
            get
            {
                if (Request["Typecode"] == null)
                {
                    return string.Empty;
                }
                return Request["Typecode"];
            }
        }



        /// <summary>
        /// page load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, System.EventArgs e)
        {


            if (!IsPostBack)
            {
                //lblcid.Text = AppContext.LcidCnName(AppContext.LCID);
                
               
                if (this.seqno != "0")
                {
                    Market news = MarketBLL.GetInstance().Get(new Market.Key(int.Parse(this.seqno)));
                    this.txtTitle.Text = news.Title;
                    txtContent.Value = news.Content;
                    //txtcode.Text = news.Code;
                    txtShowDescr.Text = news.Showdescr;                    
                    if (!string.IsNullOrEmpty(news.Filename))
                    {

                        string file = "/Img/UpLoadFile/" + news.Filename;
                        string strfile = string.Format("<a target=_blank href='{0}' ><img src='{0}' width=100  height=100 border=0 ></a>", file);
                        if (Common.IsImg(file))
                        {
                            strfile = string.Format("<a target=_blank href='{0}' ><img src='{0}' width=100  height=100 border=0 ></a>", file);
                        }
                        else
                        {
                            strfile = string.Format("<a target=_blank href='{0}' >点击下载</a>", file);
                        }
                        //lbfile.Text = strfile;
                    }
                    txtShowIdx.Text = news.ShowIdx.ToString();
                    dateCreate.Text = news.Createdate.ToString("yyyy-MM-dd");
                    dateUpdate.Text = news.Lasteupdatedate.ToString("yyyy-MM-dd");
                    // content1.Value = news.Content;
                }
                else
                {
                    dateCreate.Text = DateTime.Now.ToString("yyyy-MM-dd");
                    dateUpdate.Text = DateTime.Now.ToString("yyyy-MM-dd");
                }
            }
        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {

        }
        #endregion


        //private string SaveFile()
        //{
        //    string sss = UploadFile.PostedFile.FileName;
        //    string patch = Server.MapPath("~/Img/UpLoadFile/") + "\\";
        //    string fileName = FileListBLL.SaveFile(UploadFile, patch);
        //    return fileName;
        //}


        /// <summary>
        /// save
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, System.EventArgs e)
        {
            Market news = new Market();

            if (this.seqno != "0")
            {
                news = MarketBLL.GetInstance().Get(new Market.Key(int.Parse(this.seqno)));
            }
            else
            {
                news.Licd = AppContext.LCID;//新增
            }
            string filename = string.Empty;// SaveFile();
            if (filename != string.Empty)
            {
                news.Filename = filename;
            }

            news.Title = txtTitle.Text;
            //news.Code = txtcode.Text.Trim();
            news.Showdescr = txtShowDescr.Text;
            if (txtShowIdx.Text != string.Empty)
            {
                news.ShowIdx = int.Parse(txtShowIdx.Text);
            }            
            news.Content = txtContent.Value;
            news.Licd = AppContext.LCID;
            news.IsValid = 1;

            news.Createdate = dateCreate.Text == string.Empty ? DateTime.Now : DateTime.Parse(dateCreate.Text);
            news.Lasteupdatedate = dateUpdate.Text == string.Empty ? DateTime.Now : DateTime.Parse(dateUpdate.Text);

            MarketBLL.GetInstance().SubMit(news);



            btnReturn_Click(null, null);
        }

        /// <summary>
        /// return
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnReturn_Click(object sender, System.EventArgs e)
        {
            Response.Redirect("MarketList.aspx?Typecode=" + this.Typecode);
        }



    }


}
